
#ifndef __MEM_H__
#define __MEM_H__

#define MEM_SIZE		1024
#define MIN_SIZE		16
#define SIZEOF_MEM		sizeof(struct mem)
	
#define MEM_ALIGNMENT                    4			/*n个字节对齐*/
#define MEM_ALIGN_SIZE(size) 			(((size) + MEM_ALIGNMENT - 1) & ~(MEM_ALIGNMENT-1))
#if 1	//64位系统
#define MEM_ALIGN(addr) 				((void *)(((unsigned int)(addr) + MEM_ALIGNMENT - 1) & ~(unsigned int)(MEM_ALIGNMENT-1)))
#else	//32位系统
#define MEM_ALIGN(addr) 				((void *)(((unsigned int)(addr) + MEM_ALIGNMENT - 1) & ~(unsigned int)(MEM_ALIGNMENT-1)))
#endif
/*
	N字节对齐
	例：4字节对齐；
	
	MEM_ALIGN_SIZE(7)		((7 + 4 - 1) & ~(4-1)) = （10 & ~3） = （0b0000 1010） & （0b1111 1100） = 8
	
	例：地址为 addr =0x00000007
	
		((void *)(((unsigned int)(0x00000007) + 4 - 1) & ~(unsigned int)(4-1)))
	=	((void *)(10 & ~(unsigned int)(3)))
	=	(void *)(0b0000 1010 & 0b1111 1100) = 8	
	
*/

//mem_size_t定义的大小与整个内存堆大小相关，若内存堆小可用uin16_t 若大可用uin32_t
typedef unsigned short mem_size_t ;

struct mem{
	mem_size_t next;		//下一个内存块
	mem_size_t prev;		//上一个内存块
	unsigned char used;		//使用状态 1：使用  0：未使用
};

#endif


